package com.example.flshtarvel.mapper;
import com.example.flshtarvel.entity.Notes;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface NotesMapper {
    @Insert("insert into notes(notes_id,user_id,title,message) values(#{notesId},#{userId},#{title},#{message})")
    public int insertNotes(Notes notes);

    @Update("update notes set title=#{title},message=#{message} where notes_id=#{notesId}")
    public int updateNotes(Notes notes);

    @Delete("delete from notes where notes_id=#{notesId}")
    public int deleteNotes(String notesId);

    @Select("select notes.*,likeView.like_count,collectView.collect_count from notes,(select notes.notes_id,count(love.message_id) as like_count from notes  LEFT JOIN love on notes.notes_id = love.message_id GROUP BY(notes.notes_id)) likeView, (select notes.notes_id,count(collect.message_id) as collect_count  from notes  LEFT JOIN collect on notes.notes_id = collect.message_id GROUP BY(notes.notes_id)) collectView where notes.notes_id = likeView.notes_id and notes.notes_id = collectView.notes_id ORDER BY time DESC limit #{offset},#{size} ")
    public List<Notes> selectNotes(int offset ,int size);

    @Select("select notes.*,likeView.like_count,collectView.collect_count from notes,(select notes.notes_id,count(love.message_id) as like_count from notes  LEFT JOIN love on notes.notes_id = love.message_id GROUP BY(notes.notes_id)) likeView, (select notes.notes_id,count(collect.message_id) as collect_count  from notes  LEFT JOIN collect on notes.notes_id = collect.message_id GROUP BY(notes.notes_id)) collectView where notes.notes_id = likeView.notes_id and notes.notes_id = collectView.notes_id and notes.notes_id = #{notesId}")
    public Notes selectNotesByNotesId(String notesId);

    @Select("select * from notes where user_id=#{userId}")
    public List<Notes> selectNotesByUserId(String userId);

    @Select("select * from notes where notes_id=#{notesId}")
    public Notes selectNotesById(String notesId);
}
